#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
#include<unordered_set>
using namespace std;


struct TreeNode{
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode(int x):val(x), left(nullptr), right(nullptr){}
};

class Solution{
    private:
    vector<int> val;

    public:
    int ans1(TreeNode* root){
        inorder(root, val);
        int ret = val.size();
        val.clear();
        return ret;
    }

    void inorder(TreeNode* root, vector<int>& val){
        if(root == nullptr){
            return;
        }

        inorder(root->left, val);
        val.push_back(root->val);
        inorder(root->right, val);
    }

};

TreeNode* createTree(vector<int>& num, int index, int len){
    if(num[index] == '#'){
        return NULL;
    }
    TreeNode* root = new TreeNode(num[index]);

    if(index * 2 + 1 < len){
        root->left = createTree(num, index * 2 + 1, len);
    }else{
        root->left = nullptr;
    }
    if(index * 2 + 2 < len){
        root->right = createTree(num, index * 2 + 2, len);
    }else{
        root->right = nullptr;
    }

    return root;
    }

void test1(){
    vector<int> num = {1,2,3,4,5,6};
    TreeNode* root = createTree(num, 0, num.size());
    Solution s;
    int ret = s.ans1(root);
    cout << ret << endl;
    
}

void test2(){
    vector<int> num = {1};
    TreeNode* root = createTree(num, 0, num.size());
    Solution s;
    int ret = s.ans1(root);
    cout << ret << endl;
    
}


int main(void){
    test1();
    test2();

    return 0;
}